﻿using FriendStar.Application.MainData;
using FriendStar.Code;
using FriendStar.Domain.Entity.MainData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FriendStar.Web.Areas.MainData.Controllers
{
    public class StoProReserviorController : ControllerBase
    {
        //
        // GET: /MainData/StoProReservior/
        ZSJ_B1_GH_SupplierInformationApp zsj_b1_gh_supplierinformationApp = new ZSJ_B1_GH_SupplierInformationApp();
        CPK_81_CB_ReserveDeviceApp cpk_81_cb_reservedeviceApp = new CPK_81_CB_ReserveDeviceApp();        
        V_CPK_81_CB_ReserveDeviceApp v_cpk_81_cb_reservedeviceApp = new V_CPK_81_CB_ReserveDeviceApp();
        V_JSK_81_CB_ReserveDeviceApp v_jsk_81_cb_reservedeviceApp = new V_JSK_81_CB_ReserveDeviceApp();
        V_WWK_81_CB_ReserveDeviceApp v_wwk_81_cb_reservedeviceApp = new V_WWK_81_CB_ReserveDeviceApp();
        V_RQK_41_CB_ReserveDeviceApp v_rqk_41_cb_reservedeviceApp = new V_RQK_41_CB_ReserveDeviceApp();
        RQK_41_CB_ReserveDeviceApp rqk_41_cb_reservedeviceApp = new RQK_41_CB_ReserveDeviceApp();
        V_CLK_81_CB_ReserveDeviceApp v_clk_81_cb_reservedeviceApp = new V_CLK_81_CB_ReserveDeviceApp();
        CLK_81_CB_ReserveDeviceApp clk_81_cb_reservedeviceApp = new CLK_81_CB_ReserveDeviceApp();
        V_FLK_31_CB_ReserveDeviceApp v_flk_31_cb_reservedeviceApp = new V_FLK_31_CB_ReserveDeviceApp();
        FLK_31_CB_ReserveDeviceApp flk_31_cb_reservedeviceApp = new FLK_31_CB_ReserveDeviceApp();

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StoProReserviorCP()
        {
            ViewBag.fproCompany = zsj_b1_gh_supplierinformationApp.GetList("IsSupplier ='1'");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoProReserviorCPJson(Pagination pagination, string FProductionNO, string FProductionName, string FProCompanyNO)
        {
            var data = new
            {
                rows = v_cpk_81_cb_reservedeviceApp.GetList(pagination, FProductionNO, FProductionName, FProCompanyNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StoProReserviorJS()
        {
            ViewBag.fproCompany = zsj_b1_gh_supplierinformationApp.GetList("IsSupplier ='1'");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoProReserviorJSJson(Pagination pagination, string FProductionNO, string FProductionName, string FProCompanyNO)
        {
            var data = new
            {
                rows = v_jsk_81_cb_reservedeviceApp.GetList(pagination, FProductionNO, FProductionName, FProCompanyNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StoProReserviorWW()
        {
            ViewBag.fproCompany = zsj_b1_gh_supplierinformationApp.GetList("IsSupplier ='1'");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoProReserviorWWJson(Pagination pagination, string FProductionNO, string FProductionName, string FProCompanyNO)
        {
            var data = new
            {
                rows = v_wwk_81_cb_reservedeviceApp.GetList(pagination, FProductionNO, FProductionName, FProCompanyNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorForm(string status, CPK_81_CB_ReserveDeviceEntity entity)
        {
            if (status == "U")
            {
                CPK_81_CB_ReserveDeviceEntity oldEntity = cpk_81_cb_reservedeviceApp.GetForm(entity.FProductionNO, entity.FProCompanyNO, entity.FStoreNO);
                if (oldEntity != null)
                {
                    cpk_81_cb_reservedeviceApp.FullUpdate(entity);
                }
                else
                {
                    entity.FMaintainStatus = "0";
                    cpk_81_cb_reservedeviceApp.SubmitForm(entity, "");
                }
                return Success("输入操作成功。");
            }
            else if (status == "D")
            {

                CPK_81_CB_ReserveDeviceEntity oldEntity = cpk_81_cb_reservedeviceApp.GetForm(entity.FProductionNO, entity.FProCompanyNO, entity.FStoreNO);
                if (oldEntity != null)
                {
                    cpk_81_cb_reservedeviceApp.DeleteForm(entity.FProductionNO, entity.FProCompanyNO, entity.FStoreNO);
                }
                return Success("清除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorStatus(string keyValue)
        {
            string[] array = keyValue.Split(',');
            string ids = "";
            foreach (string str in array)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    ids += "'" + str + "',";
                }
            }
            ids = ids.TrimEnd(',');
            if(ids != "")
            {
                cpk_81_cb_reservedeviceApp.SetStoProReserviorStatus(ids);
            }
            return Success("发布操作成功。");
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StoProReserviorRQ()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoProReserviorRQJson(Pagination pagination, string FContainerNO, string FContainerName)
        {
            var data = new
            {
                rows = v_rqk_41_cb_reservedeviceApp.GetList(pagination, FContainerNO, FContainerName),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
    
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorRQForm(string status, RQK_41_CB_ReserveDeviceEntity entity)
        {
            if (status == "U")
            {
                RQK_41_CB_ReserveDeviceEntity oldEntity = rqk_41_cb_reservedeviceApp.GetForm(entity.FContainerNO);
                if (oldEntity != null)
                {
                    rqk_41_cb_reservedeviceApp.FullUpdate(entity);
                }
                else
                {
                    entity.FMaintainStatus = "0";
                    rqk_41_cb_reservedeviceApp.SubmitForm(entity, "");
                }
                return Success("输入操作成功。");
            }
            else if (status == "D")
            {
                RQK_41_CB_ReserveDeviceEntity oldEntity = rqk_41_cb_reservedeviceApp.GetForm(entity.FContainerNO);
                if (oldEntity != null)
                {
                    rqk_41_cb_reservedeviceApp.DeleteForm(entity.FContainerNO);
                }
                return Success("清除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorRQStatus(string keyValue)
        {
            string[] array = keyValue.Split(',');
            string ids = "";
            foreach (string str in array)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    ids += "'" + str + "',";
                }
            }
            ids = ids.TrimEnd(',');
            if (ids != "")
            {
                rqk_41_cb_reservedeviceApp.SetStoProReserviorStatus(ids);
            }
            return Success("发布操作成功。");
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StoProReserviorCL()
        {
            ViewBag.fproCompany = zsj_b1_gh_supplierinformationApp.GetList("IsMaterial ='1'");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoProReserviorCLJson(Pagination pagination, string MaterialCode, string MaterialSizes, string FProCompanyNO)
        {
            var data = new
            {
                rows = v_clk_81_cb_reservedeviceApp.GetList(pagination, MaterialCode, MaterialSizes, FProCompanyNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorCLForm(string status, CLK_81_CB_ReserveDeviceEntity entity)
        {
            if (status == "U")
            {
                CLK_81_CB_ReserveDeviceEntity oldEntity = clk_81_cb_reservedeviceApp.GetForm(entity.MaterialCode, entity.MaterialSizes, entity.FProCompanyNO, entity.StandardNumber, entity.MaterialDemand, entity.MaterialNO);
                if (oldEntity != null)
                {
                    clk_81_cb_reservedeviceApp.FullUpdate(entity);
                }
                else
                {
                    entity.FMaintainStatus = "0";
                    clk_81_cb_reservedeviceApp.SubmitForm(entity, "");
                }
                return Success("输入操作成功。");
            }
            else if (status == "D")
            {
                CLK_81_CB_ReserveDeviceEntity oldEntity = clk_81_cb_reservedeviceApp.GetForm(entity.MaterialCode, entity.MaterialSizes, entity.FProCompanyNO, entity.StandardNumber, entity.MaterialDemand, entity.MaterialNO);
                if (oldEntity != null)
                {
                    clk_81_cb_reservedeviceApp.DeleteForm(entity.MaterialCode, entity.MaterialSizes, entity.FProCompanyNO, entity.StandardNumber, entity.MaterialDemand, entity.MaterialNO);
                }
                return Success("清除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorCLStatus(string keyValue)
        {
            string[] array = keyValue.Split(',');
            string ids = "";
            foreach (string str in array)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    ids += "'" + str + "',";
                }
            }
            ids = ids.TrimEnd(',');
            if (ids != "")
            {
                clk_81_cb_reservedeviceApp.SetStoProReserviorStatus(ids);
            }
            return Success("发布操作成功。");
        }


        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StoProReserviorFL()
        {
            ViewBag.fproCompany = zsj_b1_gh_supplierinformationApp.GetList("IsAccessories ='1'");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoProReserviorFLJson(Pagination pagination, string AccessoriesNO, string AccessoriesName, string FProCompanyNO)
        {
            var data = new
            {
                rows = v_flk_31_cb_reservedeviceApp.GetList(pagination, AccessoriesNO, AccessoriesName, FProCompanyNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorFLForm(string status, FLK_31_CB_ReserveDeviceEntity entity)
        {
            if (status == "U")
            {
                FLK_31_CB_ReserveDeviceEntity oldEntity = flk_31_cb_reservedeviceApp.GetForm(entity.AccessoriesNO, entity.FProCompanyNO);
                if (oldEntity != null)
                {
                    flk_31_cb_reservedeviceApp.FullUpdate(entity);
                }
                else
                {
                    entity.FMaintainStatus = "0";
                    flk_31_cb_reservedeviceApp.SubmitForm(entity, "");
                }
                return Success("输入操作成功。");
            }
            else if (status == "D")
            {
                FLK_31_CB_ReserveDeviceEntity oldEntity = flk_31_cb_reservedeviceApp.GetForm(entity.AccessoriesNO, entity.FProCompanyNO); 
                if (oldEntity != null)
                {
                    flk_31_cb_reservedeviceApp.DeleteForm(entity.AccessoriesNO, entity.FProCompanyNO);
                }
                return Success("清除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStoProReserviorFLStatus(string keyValue)
        {
            string[] array = keyValue.Split(',');
            string ids = "";
            foreach (string str in array)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    ids += "'" + str + "',";
                }
            }
            ids = ids.TrimEnd(',');
            if (ids != "")
            {
                flk_31_cb_reservedeviceApp.SetStoProReserviorStatus(ids);
            }
            return Success("发布操作成功。");
        }
    }
}
